﻿namespace DynamicChart.Service.FunctionConversion;

public class MySqlAdapter : ISqlFunctionAdapter
{
    public string DateConvert(string fieldName, string format = null)
    {
        string mysqlFormat = format == null ? ":dateType" : format;
        return $"DATE_FORMAT({fieldName}, '{mysqlFormat}')";
    }

    public string DefaultConvert(string functionName, string fieldName)
    {
        return $"{functionName}({fieldName})";
    }

    public string FormatValue(string value)
    {
        return value;
    }

    public string GetDateFormat(string format)
    {
        switch (format)
        {
            case "day":
                return "%Y-%m-%d";
            case "month":
                return "%Y-%m";
            default:
                return "%Y";
        }
    }

    public string LikeConvert(string fieldName, string parameterName)
    {
        return $"{fieldName} like '%:{parameterName}%'";
    }

    public string EmptyConvert(string fieldName)
    {
        return fieldName;
    }
}